/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.bluepumpkin;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Trong Nguyen
 */
@Entity
@Table(name = "Event")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Event.findAll", query = "SELECT e FROM Event e ORDER BY e.startRegDate DESC"),
    @NamedQuery(name = "Event.findById", query = "SELECT e FROM Event e WHERE e.id = :id"),
    @NamedQuery(name = "Event.findByTitle", query = "SELECT e FROM Event e WHERE e.title = :title"),
    @NamedQuery(name = "Event.findByPhoto", query = "SELECT e FROM Event e WHERE e.photo = :photo"),
    @NamedQuery(name = "Event.findByStartRegDate", query = "SELECT e FROM Event e WHERE e.startRegDate = :startRegDate"),
    @NamedQuery(name = "Event.findByEndRegDate", query = "SELECT e FROM Event e WHERE e.endRegDate = :endRegDate"),
    @NamedQuery(name = "Event.findByStartDate", query = "SELECT e FROM Event e WHERE e.startDate = :startDate"),
    @NamedQuery(name = "Event.findByEndDate", query = "SELECT e FROM Event e WHERE e.endDate = :endDate"),
    @NamedQuery(name = "Event.findByMinPlayers", query = "SELECT e FROM Event e WHERE e.minPlayers = :minPlayers"),
    @NamedQuery(name = "Event.findByMaxPlayers", query = "SELECT e FROM Event e WHERE e.maxPlayers = :maxPlayers"),
    @NamedQuery(name = "Event.findByActive", query = "SELECT e FROM Event e WHERE e.active = :active")})
public class Event implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
//    @NotNull
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 250)
    @Column(name = "title")
    private String title="";
    @Size(max = 150)
    @Column(name = "photo")
    private String photo="";
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 2147483647)
    @Column(name = "description")
    private String description="";
    @Basic(optional = false)
    @NotNull
    @Column(name = "startRegDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startRegDate ;
    @Basic(optional = false)
    @NotNull
    @Column(name = "endRegDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date endRegDate ;
    @Basic(optional = false)
    @NotNull
    @Column(name = "startDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startDate=new Date();
    @Basic(optional = false)
    @NotNull
    @Column(name = "endDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date endDate;
    @Column(name = "minPlayers")
    private Integer minPlayers;
    @Column(name = "maxPlayers")
    private Integer maxPlayers ;
    @Basic(optional = false)
    @NotNull
    @Column(name = "active")
    private boolean active=true;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private List<Registration> registrationList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private List<CommentsList> commentsListList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private List<Prize> prizeList;

    public Event() {
    }

    public Event(Integer id) {
        this.id = id;
    }

    public Event(Integer id, String title, String description, Date startRegDate, Date endRegDate, Date startDate, Date endDate, boolean active) {
        this.id = id;
        this.title = title;
        this.description = description;
        this.startRegDate = startRegDate;
        this.endRegDate = endRegDate;
        this.startDate = startDate;
        this.endDate = endDate;
        this.active = active;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
       return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public String getDescription() {
        return  description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getStartRegDate() {
        return startRegDate;
    }

    public void setStartRegDate(Date startRegDate) {
        this.startRegDate = startRegDate;
    }

    public Date getEndRegDate() {
        return endRegDate;
    }

    public void setEndRegDate(Date endRegDate) {
        this.endRegDate = endRegDate;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Integer getMinPlayers() {
        return minPlayers;
    }

    public void setMinPlayers(Integer minPlayers) {
        this.minPlayers = minPlayers;
    }

    public Integer getMaxPlayers() {
        return maxPlayers;
    }

    public void setMaxPlayers(Integer maxPlayers) {
        this.maxPlayers = maxPlayers;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @XmlTransient
    public List<Registration> getRegistrationList() {
        return registrationList;
    }

    public void setRegistrationList(List<Registration> registrationList) {
        this.registrationList = registrationList;
    }

    @XmlTransient
    public List<CommentsList> getCommentsListList() {
        return commentsListList;
    }

    public void setCommentsListList(List<CommentsList> commentsListList) {
        this.commentsListList = commentsListList;
    }

    @XmlTransient
    public List<Prize> getPrizeList() {
        return prizeList;
    }

    public void setPrizeList(List<Prize> prizeList) {
        this.prizeList = prizeList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Event)) {
            return false;
        }
        Event other = (Event) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return id+"";
    }
    
}
